import http from '@/utils/http'

const BASE_URL = '/knowledge/knowledge'

export interface KnowledgeResp {
  fileName: string
  physicalPath: string
  logicalPath: string
  parentFolderId: string
  fileSize: string
  fileType: string
  isFolder: string
  createdBy: string
  createdAt: string
  updatedAt: string
  isDeleted: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}
export interface KnowledgeDetailResp {
  fileId: string
  fileName: string
  physicalPath: string
  logicalPath: string
  parentFolderId: string
  fileSize: string
  fileType: string
  isFolder: string
  createdBy: string
  createdAt: string
  updatedAt: string
  isDeleted: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}
export interface KnowledgeQuery {
  fileName: string
  physicalPath: string
  logicalPath: string
  fileType: string
  createdBy: string
  createdAt: string
  updatedAt: string
  createUser: string
  createTime: string
  isFolder: boolean
  sort: Array<string>
}
export interface KnowledgePageQuery extends KnowledgeQuery, PageQuery {}

/** @desc 查询知识库管理列表 */
export function listKnowledge(query: KnowledgePageQuery) {
  return http.get<PageRes<KnowledgeResp[]>>(`${BASE_URL}`, query)
}

export function listKnowledgeByFileName(fileName: string, parentFolderId: number) {
  return http.get<PageRes<KnowledgeResp[]>>(`${BASE_URL}/fileName`)
}

/** @desc 查询知识库管理详情 */
export function getKnowledge(id: string) {
  return http.get<KnowledgeDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增知识库管理 */
export function addKnowledge(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改知识库管理 */
export function updateKnowledge(data: any) {
  return http.put(`${BASE_URL}/update`, data)
}

/** @desc 删除知识库管理 */
export function deleteKnowledge(id: string, physicalPath: string, isFolder: boolean) {
  return http.del(`${BASE_URL}/delete/${id}`, {physicalPath, isFolder})
}

/** @desc 导出知识库管理 */
export function exportKnowledge(query: KnowledgeQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}

export function addFolder(data: any) {
  return http.post(`${BASE_URL}/folders`, data)
}

export function askDeepseek(data: any) {
  return http.post(`${BASE_URL}/ask`, data)
}
